/*
Source : https://leetcode.com/problems/reverse-integer/
Author : nflush@outlook.com
Date   : 2016-05-19
*/
/*
28. Implement strStr()
Total Accepted: 107265 Total Submissions: 428227 Difficulty: Easy

Implement strStr().

Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.

Subscribe to see which companies asked this question
*/

class Solution {
private:
    bool issameStr(string &haystack, string &needle, int start, int len){
        while(len-- ){
            if(haystack[start+len] != needle[len]){
                return false;
            }
        }
        return true;
    }
public:
    int strStr(string haystack, string needle) {
        int s1 = haystack.size();
        int s2 = needle.size();
        if (s1 < s2){
            return -1;
        }
        for (int x= 0; x <= s1-s2; x++){
            if(issameStr(haystack, needle, x, s2)){
                return x;
            }
        }
        return -1;
    }
};

